<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Record extends Model
{
    protected $guarded = [];

    public static function boot()
    {
        parent::boot();

        static::created(function ($record) {
            if ($record->it > 35) {
                $record->log()->create([
                    'it' => $record->it * 10,
                    'product_id' => $record->product_id,
                    'created_at' => $record->created_at,
                    'updated_at' => $record->updated_at,
                ]);
            }
        });
    }

    public function log()
    {
        return $this->hasOne(Log::class);
    }

    public function product()
    {
        return $this->belongsTo(Product::class);
    }


    public function getItAttribute($value)
    {
        return $value/10;
    }

    public function getEtAttribute($value)
    {
        return $value/10;
    }

    public function getRhAttribute($value)
    {
        return $value/10;
    }
}
